package com.example;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.bean.SystemBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@SpringBootApplication
public class SpringbootApolloApplication implements CommandLineRunner{

	@Autowired
	private SystemBean systemBean;

	static List<String> list = new ArrayList<>();

	public static void main(String[] args) {
		SpringApplication.run(SpringbootApolloApplication.class, args);
	}

	@Override
	public void run(String... strings) throws Exception {
//		Config config = ConfigService.getAppConfig();
//		//config instance is singleton for each namespace and is never null
//		String someKey = "timeout";
//		String someDefaultValue = "none";
//		String value = config.getProperty(someKey, someDefaultValue);
//		System.out.println(value);

		list.add("test_init");
	}

	@RequestMapping("getActivity")
	public String getActivity(String configName){
		JSONObject jsonObject = JSON.parseObject(String.valueOf(systemBean.getActivity().get(configName)));
		System.out.println(jsonObject.toJSONString());
		return "ok";
	}

	@RequestMapping("getSystem")
	public String getSystem(String configName){
		System.out.println(systemBean.getSystem().get(configName));
		return "ok";
	}

	@RequestMapping("configAll")
	public String getConfigAll(){
		System.out.println(systemBean.getActivity());
		System.out.println(systemBean.getSystem());
		return "ok";
	}

//	@RequestMapping("/test")
//	public String test(){
//		return systemBean.getTimeout()+"";
//	}
//
//	@RequestMapping("/count")
//	public String count(){
//		return systemBean.getCount()+"";
//	}
//
//	@RequestMapping("/activity_001")
//	public String activity_001(){
//
//		JSONObject jsonObject = JSONObject.parseObject(systemBean.getActivity_001());
//		System.out.println(jsonObject.getString("start_time"));
//		System.out.println(jsonObject.getString("end_time"));
//		System.out.println(jsonObject.toJSONString());
//		return systemBean.getActivity_001()+"";
//	}
//
//	@RequestMapping("/list")
//	public String cpu() throws Exception {
//		System.out.println(list);
//
//		return "ok";
//	}
//
//	@RequestMapping("/update")
//	public String update() throws Exception {
//		list = new ArrayList<>();
//		list.add("test");
//		System.out.println(list);
//
//		return "ok";
//	}

}
